<?php get_instance()->view('common/header');?>
<style>
	.box.box-info {
		border-top-color: #e6e6e6;
	}
	.box-header {
		color: #444;
		display: block;
		padding: 10px;
		position: relative;
	}
	.box {
		position: relative;
		border-radius: 3px;
		background: #ffffff;
		border-top: 3px solid #d2d6de;
		margin-bottom: 20px;
		width: 100%;
		box-shadow: 0 1px 1px rgba(0,0,0,0.1);
	}
    #list-table>thead>tr>th{text-align: center;}
</style>
<div class="page-container wrapper">
	<!-- BEGIN SIDEBAR -->
    <?php get_instance()->view('common/sidebar');?>
	<!-- END SIDEBAR -->
	<!-- BEGIN CONTENT -->
	<div class="page-content-wrapper">
		<div class="page-content" style="min-height:1200px !important">
			<!-- BEGIN PAGE HEADER-->
			<div class="col-xs-12">
				<div class="">
                    <div class="row">
                        <div class="col-md-12">
                            <h3 class="page-title">新用户统计</h3>
                            <ul class="page-breadcrumb breadcrumb">
                                <li><i class="fa fa-home"></i>新用户统计</li>
                            </ul>
                        </div>
                    </div>
					<div class="row">
						<div class="col-md-12">
							<div class="box box-info">
								<div class="box-header with-border">
									<div class="row">
										<div class="col-md-12">
                                            <div class="col-xs-5">
                                                <div class="input-group margin">
                                                    <div class="input-group-addon">选择时间  <i class="fa fa-calendar"></i></div>
                                                    <input type="text" class="form-control form-filter pull-right" name="time" value="<?php echo $time?>" dp>
                                                </div>
                                            </div>
                                            <div class="col-xs-3">
                                                <div class="input-group margin">
                                                    <div class="input-group-addon">状态</div>
                                                    <select class="form-control form-filter" name="status" multiple="multiple">
                                                        <?php foreach ($status as $sk => $s):?>
                                                            <option value="<?php echo $sk?>"  ><?php echo $s?></option>
                                                        <?php endforeach;?>
                                                    </select>
                                                </div>
                                            </div>
                                            <?php if(adminAuthority('consumer-export', 'statistics')):?>
                                                <div class="col-xs-2"><a class="btn btn-block export blue" href="javascript:;">导出</a></div>
                                                <div class="col-xs-2 "><input class="btn btn-block btn-info green btn-default save" type="submit" value="确定"></div>
                                            <?php else:?>
                                                <div class="col-xs-2 col-xs-offset-2"><input class="btn btn-block btn-info green btn-default save" type="submit" value="确定"></div>
                                            <?php endif;?>

										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
                    <div class="row">
                        <div class="col-md-12">
                            <!-- Begin: life time stats -->
                            <div class="portlet box blue tabbable">
                                <div class="portlet-title">
                                    <div class="caption"><i class="fa fa-bar-chart-o"></i>新用户下单信息</div>
                                </div>
                                <div class="portlet-body">
                                    <div class="well no-margin no-border">
                                        <div class="row">
                                            <div class="col-md-6">
                                                <div class="col-md-3 col-sm-3 col-xs-6 text-stat">
                                                    <span class="label label-success">
                                                         新增注册用户数：
                                                    </span>
                                                    <h3 class="total_consumer"><?php echo $order['total_consumer']?></h3>
                                                </div>
                                                <div class="col-md-3 col-sm-3 col-xs-6 text-stat">
                                                    <span class="label label-success">
                                                         首次下单用户数：
                                                    </span>
                                                    <h3 class="total_user"><?php echo $order['total_user']?></h3>
                                                </div>
                                                <div class="col-md-3 col-sm-3 col-xs-6 text-stat">
                                                    <span class="label label-info">
                                                         新用户订单总量：
                                                    </span>
                                                    <h3 class="total_order"><?php echo $order['total_order'] ?></h3>
                                                </div>
                                                <div class="col-md-3 col-sm-3 col-xs-6 text-stat">
                                                    <span class="label label-info">
                                                         新用户关闭订单数：
                                                    </span>
                                                    <h3 class="close_order"><?php echo $order['close_order'] ?></h3>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="col-md-3 col-sm-3 col-xs-6 text-stat">
                                                    <span class="label label-info">
                                                         新用户客单价：
                                                    </span>
                                                    <h3 class="single_amount"><?php echo $order['single_amount']?></h3>
                                                </div>
                                                <div class="col-md-3 col-sm-3 col-xs-6 text-stat">
                                                    <span class="label label-info">
                                                         新用户订单总额：
                                                    </span>
                                                    <h3 class="total_amount"><?php echo $order['total_amount']?></h3>
                                                </div>
                                                <div class="col-md-3 col-sm-3 col-xs-6 text-stat">
                                                    <span class="label label-warning">
                                                         新用户订单实付总额：
                                                    </span>
                                                    <h3 class="reality_amount"><?php echo $order['reality_amount']?></h3>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!-- End: life time stats -->
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-12">
                            <div class="portlet">
                                <div class="portlet-body">
                                    <ul class="nav nav-tabs" role="tablist">
                                        <li role="presentation" class="active">
                                            <a href="#orderlist" aria-controls="date" role="tab" data-toggle="tab"><i class="fa fa-list"></i>订单列表</a>
                                        </li>
                                        <li role="presentation">
                                            <a href="#newuser" aria-controls="merchant" role="tab" data-toggle="tab"><i class="fa fa-list"></i>新用户列表</a>
                                        </li>
                                        <li role="presentation">
                                            <a href="#firstuser" aria-controls="merchant" role="tab" data-toggle="tab"><i class="fa fa-list"></i>首次下单用户</a>
                                        </li>
                                    </ul>
                                    <div class="tab-content">
                                        <div role="tabpanel" class="tab-pane active" id="orderlist">
                                            <div class="panel panel-default">
                                                <div class="panel-body">
                                                    <div class="table-container">
                                                        <div class="table-actions-wrapper"> <span> </span></div>
                                                        <table class="table table-bordered table-hover" id="datatable">
                                                            <thead>
                                                            <tr role="row" class="heading">
                                                                <th></th>
                                                                <th width="80px" sort="false">ID</th>
                                                                <th sort="false">订单号</th>
                                                                <th sort="false">会员手机</th>
                                                                <th sort="false">商品总价</th>
                                                                <th sort="false">物流价格</th>
                                                                <th sort="false">实付金额</th>
                                                                <th sort="false">订单优惠</th>
                                                                <th sort="false">下单日期</th>
                                                                <th sort="false">状态</th>
                                                                <th sort="false">操作</th>
                                                            </tr>
                                                            </thead>
                                                            <tbody></tbody>
                                                        </table>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div role="tabpanel" class="tab-pane" id="newuser">
                                            <div class="panel panel-default">
                                                <div class="panel-body">
                                                    <table class="table table-bordered table-hover" id="newuserdatatable">
                                                        <thead>
                                                            <tr role="row" class="heading">
                                                                <th width="100px"> 头像 </th>
                                                                <th width="10%" > 昵称 </th>
                                                                <th width="10%" sort="false">电话</th>
                                                                <th width="10%" sort="false">真实姓名</th>
                                                                <th width="10%" sort="false">余额</th>
                                                                <th width="8%" sort="false">性别</th>
                                                                <th width="10%" sort="false">注册时间</th>
                                                                <th width="14%" sort="false">最后登录</th>
                                                                <th width="15%" sort="false">操作</th>
                                                            </tr>
                                                        </thead>
                                                        <tbody></tbody>
                                                    </table>
                                                </div>
                                            </div>
                                        </div>
                                        <div role="tabpanel" class="tab-pane" id="firstuser">
                                            <div class="panel panel-default">
                                                <div class="panel-body">
                                                    <table class="table table-bordered table-hover" id="firstuserdatatable">
                                                        <thead>
                                                        <tr role="row" class="heading">
                                                            <th width="100px"> 头像 </th>
                                                            <th width="10%" > 昵称 </th>
                                                            <th width="10%" sort="false">电话</th>
                                                            <th width="10%" sort="false">真实姓名</th>
                                                            <th width="10%" sort="false">余额</th>
                                                            <th width="8%" sort="false">性别</th>
                                                            <th width="10%" sort="false">注册时间</th>
                                                            <th width="14%" sort="false">下单时间</th>
                                                            <th width="15%" sort="false">操作</th>
                                                        </tr>
                                                        </thead>
                                                        <tbody></tbody>
                                                    </table>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
				</div>
			</div>
            <div style="clear: both"></div>
		</div>
	</div>
</div>
<!-- END CONTENT -->
</div>
<script type="text/javascript">
	$(document).ready(function() {
        $('[name="status"]').select2({allowClear:true});
        datatable_init({
            "sDom": "<'row'<'col-md-5 col-sm-12'<'table-group-actions pull-right'>>r><'table-scrollable't><'row'<'col-md-8 col-sm-12'pli><'col-md-4 col-sm-12'>r>>",
            src: $("#datatable"),
            sAjaxSource: "<?php echo getUrl('statistics/consumer/getList');?>",
            aoColumnDefs : [
                {
                    'bSortable' : false,
                    'aTargets' : [0,1,2,3,7]
                },
                { "bVisible": false, "aTargets":[0]}
            ]
        });
        datatable_init({
            "sDom": "<'row'<'col-md-5 col-sm-12'<'table-group-actions pull-right'>>r><'table-scrollable't><'row'<'col-md-8 col-sm-12'pli><'col-md-4 col-sm-12'>r>>",
            src: $("#newuserdatatable"),
            sAjaxSource: "<?php echo getUrl('statistics/consumer/getNewUserList');?>",
            aoColumnDefs : [{
                'bSortable' : false,
                'aTargets' : [0,1,2,3,4,5,6,7,8]
            }]
        });
        datatable_init({
            "sDom": "<'row'<'col-md-5 col-sm-12'<'table-group-actions pull-right'>>r><'table-scrollable't><'row'<'col-md-8 col-sm-12'pli><'col-md-4 col-sm-12'>r>>",
            src: $("#firstuserdatatable"),
            sAjaxSource: "<?php echo getUrl('statistics/consumer/getFirstUserlist');?>",
            aoColumnDefs : [{
                'bSortable' : false,
                'aTargets' : [0,1,2,3,4,5,6,7,8]
            }]
        });

        $('[dp]').not("[noinit]").datepicker({
            changeMonth: true,
            autoclose: true,
            format: "yyyy-mm-dd",
            language: 'zh-CN'
        });

        $(".save").click(function () {
            var time = $("[name='time']").val();
            var status = $("[name='status']").val();
            var url = "<?php echo getUrl('statistics/consumer/detail')?>";
            $.post(url,{time:time,status:status},function(data){
                for (var k in data.data){
                    $('.'+k).text(data.data[k]);
                }
                $("#datatable").dataTable().fnDraw(true);
                $("#newuserdatatable").dataTable().fnDraw(true);
                $("#firstuserdatatable").dataTable().fnDraw(true);
            }, 'json');
        });

	});
	
	$(function () {
        $(".export").click(function () {
            var time = $("[name='time']").val();
            var status = $("[name='status']").val();
            var url = '';
            if(status){
                url += '&status='+status;
            }
            window.location.href = "<?php echo getUrl('statistics/consumer/export?time=')?>"+time + url
        })
    })
</script>
</body>
</html>